<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="剧本名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productName', validatorRules.productName]" placeholder="请输入剧本名称"></a-input>
        </a-form-item>
        <a-form-item label="货号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'itemNumber', validatorRules.itemNumber]" placeholder="请输入货号"></a-input>
        </a-form-item>
        <a-form-item label="批次" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'itemPatch', validatorRules.itemPatch]" placeholder="请输入批次"></a-input>
        </a-form-item>
        <a-form-item label="类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'itemType', validatorRules.itemType]" placeholder="请输入类别"></a-input>
        </a-form-item>
        <a-form-item label="总量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number :min="1" v-decorator="[ 'total', validatorRules.total]" placeholder="请输入总量" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="销售总量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number :min="1" v-decorator="[ 'saleTotal', validatorRules.saleTotal]" placeholder="请输入销售总量" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择生产日期" v-decorator="[ 'makeDate', validatorRules.makeDate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="类目编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'catalogId', validatorRules.catalogId]" placeholder="请输入类目编号"></a-input>
        </a-form-item>
        <a-form-item label="设置标签" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-multi-select-tag type="checkbox" v-decorator="['labelTags', validatorRules.labelTags]" :trigger-change="true" dictCode="product_label" placeholder="请选择设置标签"/>
        </a-form-item>
        <a-form-item label="作者" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'author', validatorRules.author]" placeholder="请输入作者"></a-input>
        </a-form-item>
        <a-form-item label="零售价格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'wholesalePrice', validatorRules.wholesalePrice]" placeholder="请输入零售价格"></a-input>
        </a-form-item>
        <a-form-item label="物品码载体" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'itemCode', validatorRules.itemCode]" placeholder="请输入物品码载体"></a-input>
        </a-form-item>
        <a-form-item label="Logo" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['logo', validatorRules.logo]" :trigger-change="true"></j-upload>
        </a-form-item>
        <a-form-item label="剧本实拍图" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['productImages', validatorRules.productImages]" :trigger-change="true"></j-upload>
        </a-form-item>
        <a-form-item label="剧本海报" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['playbillPoster', validatorRules.playbillPoster]" :trigger-change="true"></j-upload>
        </a-form-item>
        <a-form-item label="人物海报" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['personPoster', validatorRules.personPoster]" :trigger-change="true"></j-upload>
        </a-form-item>
        <a-form-item label="正式发行时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择正式发行时间" v-decorator="[ 'publicTime', validatorRules.publicTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="预售发行时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择预售发行时间" v-decorator="[ 'proPublicTime', validatorRules.proPublicTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="大概销量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'preSaleTotal', validatorRules.preSaleTotal]" placeholder="请输入大概销量"></a-input>
        </a-form-item>
        <a-form-item label="预估零售价格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'preWholesalePrice', validatorRules.preWholesalePrice]" placeholder="请输入预估零售价格"></a-input>
        </a-form-item>
        <a-form-item label="剧本人数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number :min="1" v-decorator="[ 'playbillNumber', validatorRules.playbillNumber]" placeholder="请输入剧本人数" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="剧本形式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-multi-select-tag type="checkbox" v-decorator="['playbillForm', validatorRules.playbillForm]" :trigger-change="true" dictCode="playbiil_form" placeholder="请选择剧本形式"/>
        </a-form-item>
        <a-form-item label="剧本类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'playbillType', validatorRules.playbillType]" placeholder="请输入剧本类型"></a-input>
        </a-form-item>
        <a-form-item label="剧本背景" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-multi-select-tag type="checkbox" v-decorator="['playbillBackground', validatorRules.playbillBackground]" :trigger-change="true" dictCode="playbill_background" placeholder="请选择剧本背景"/>
        </a-form-item>
        <a-form-item label="适合人群" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-multi-select-tag type="checkbox" v-decorator="['belongtoCrowd', validatorRules.belongtoCrowd]" :trigger-change="true" dictCode="belongto_crowd" placeholder="请选择适合人群"/>
        </a-form-item>
        <a-form-item label="游戏时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'playTime', validatorRules.playTime]" placeholder="请输入游戏时间"></a-input>
        </a-form-item>
        <a-form-item label="发货时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'sendgoodTime', validatorRules.sendgoodTime]" placeholder="请输入发货时间"></a-input>
        </a-form-item>
        <a-form-item label="支持物流" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-multi-select-tag type="checkbox" v-decorator="['supportLogistics', validatorRules.supportLogistics]" :trigger-change="true" dictCode="support_logistics" placeholder="请选择支持物流"/>
        </a-form-item>
        <a-form-item label="道具支持" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['propStatus', validatorRules.propStatus]" :trigger-change="true" dictCode="prop_status" placeholder="请选择道具支持"/>
        </a-form-item>
        <a-form-item label="道具资料" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['propData', validatorRules.propData]" :trigger-change="true"></j-upload>
        </a-form-item>
        <a-form-item label="买断状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['buyoutStatus', validatorRules.buyoutStatus]" :trigger-change="true" dictCode="" placeholder="请选择买断状态"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JUpload from '@/components/jeecg/JUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  import JMultiSelectTag from "@/components/dict/JMultiSelectTag"
  
  export default {
    name: "BlockProductStandardsModal",
    components: { 
      JDate,
      JUpload,
      JDictSelectTag,
      JMultiSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          productName: {rules: [
            {required: true, message: '请输入剧本名称!'},
          ]},
          itemNumber: {rules: [
            {required: true, message: '请输入货号!'},
          ]},
          itemPatch: {rules: [
          ]},
          itemType: {rules: [
            {required: true, message: '请输入类别!'},
          ]},
          total: {rules: [
            {required: true, message: '请输入总量!'},
          ]},
          saleTotal: {rules: [
          ]},
          makeDate: {rules: [
          ]},
          catalogId: {rules: [
            {required: true, message: '请输入类目编号!'},
          ]},
          labelTags: {rules: [
          ]},
          author: {rules: [
          ]},
          wholesalePrice: {rules: [
          ]},
          itemCode: {rules: [
          ]},
          logo: {rules: [
          ]},
          productImages: {rules: [
          ]},
          playbillPoster: {rules: [
          ]},
          personPoster: {rules: [
          ]},
          publicTime: {rules: [
          ]},
          proPublicTime: {rules: [
          ]},
          preSaleTotal: {rules: [
          ]},
          preWholesalePrice: {rules: [
          ]},
          playbillNumber: {rules: [
          ]},
          playbillForm: {rules: [
          ]},
          playbillType: {rules: [
          ]},
          playbillBackground: {rules: [
          ]},
          belongtoCrowd: {rules: [
          ]},
          playTime: {rules: [
          ]},
          sendgoodTime: {rules: [
          ]},
          supportLogistics: {rules: [
          ]},
          propStatus: {rules: [
          ]},
          propData: {rules: [
          ]},
          buyoutStatus: {rules: [
          ]},
        },
        url: {
          add: "/block/blockProductStandards/add",
          edit: "/block/blockProductStandards/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'productName','itemNumber','itemPatch','itemType','total','saleTotal','makeDate','catalogId','labelTags','author','productInfo','wholesalePrice','itemCode','logo','productImages','playbillPoster','personPoster','publicTime','proPublicTime','preSaleTotal','preWholesalePrice','playbillNumber','playbillForm','playbillType','playbillBackground','belongtoCrowd','playTime','sendgoodTime','supportLogistics','propStatus','propData','buyoutStatus'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'productName','itemNumber','itemPatch','itemType','total','saleTotal','makeDate','catalogId','labelTags','author','productInfo','wholesalePrice','itemCode','logo','productImages','playbillPoster','personPoster','publicTime','proPublicTime','preSaleTotal','preWholesalePrice','playbillNumber','playbillForm','playbillType','playbillBackground','belongtoCrowd','playTime','sendgoodTime','supportLogistics','propStatus','propData','buyoutStatus'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>